/**
 * <p>Title: ServiceZMCEF7.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2012-2-21 下午05:33:02  张志芳  Create
 *</pre>
 */
package com.baosight.sczx.zm.ce.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.common.zm.cInterface.ce.Equipment;
import com.baosight.sczx.zm.ce.domain.ZMCEWorkRecord;

/**
 * <p>Title: ServiceZMCEF7.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2012-2-21 下午05:33:02  张志芳  Create
 *</pre>
 */
public class ServiceZMCEF7 extends ServiceEPBase {
	/**
	 * 初始化方法+
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *   2012-01-15 上午09:40:20 高强
	 * </p>
	 *
	 */
	public EiInfo initLoad(EiInfo inInfo) {
		EiInfo outInfo = null;
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		String fdDepartmentId = UserSession.getInSessionProperty("orgCode").toString();
		StaticTools.setQueryParameters(inInfo, "fdDepartmentId", fdDepartmentId, true);//添加查询条件 操作用户
		inInfo.getBlock(EiConstant.queryBlock).addMeta(new EiColumn("fdDepartmentId"));
		outInfo = query(inInfo);
		outInfo.addBlock(Equipment.getEquipmentBlock("cmes.ce.equipment", null));
		outInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.ce.orgName", "orgCode", "orgName", true));//列表区执行部门
		//outInfo.addBlock(User.getInstance().getConstructionStaff("cmes.ce.empName", "empCode", "empName", false));//执行人
		outInfo.addBlock(getOrderCode());//工单编号
		outInfo.addBlock(getType(true));//工单类型)
		return outInfo;
	}

	/**
	 * 设备变动查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *     2012-01-15 上午09:40:20 高强
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		String type=inInfo.getString("fdEquipmentId");
		StaticTools.setQueryParameters(inInfo, "fdEquipmentId", type, true);//添加查询条件
		EiInfo outInfo = super.query(inInfo, "ZMCEWorkRecord.query", new ZMCEWorkRecord());				
		return outInfo;
	}

	/**
	 * 
	 * <p>Function: getType</p>
	 * <p>Description: 获取工单类型的block</p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-01-15 上午09:40:20 高强
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	private EiBlock getType(boolean isAll)
	{
		EiBlock block = new EiBlock("cmes.ce.type");
		
		EiColumn eiColumn = new EiColumn("label");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("value");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		List<Map> list = new ArrayList<Map>();
		
		Map<String, String> _map;
		if(isAll) {
			_map = new HashMap<String, String>();
			_map.put("value", "");
			_map.put("label", "全部");
			list.add(_map);
		}

		_map = new HashMap<String, String>();
		_map.put("value", "润滑");
		_map.put("label", "润滑");
		list.add(_map);
		
		_map = new HashMap<String, String>();
		_map.put("value", "保养");
		_map.put("label", "保养");
		list.add(_map);
		
		_map = new HashMap<String, String>();
		_map.put("value", "大修");
		_map.put("label", "大修");
		list.add(_map);
		
		_map = new HashMap<String, String>();
		_map.put("value", "维修");
		_map.put("label", "维修");
		list.add(_map);
		
		_map = new HashMap<String, String>();
		_map.put("value", "点检");
		_map.put("label", "点检");
		list.add(_map);
		
		block.setRows(list);
		return block;
	}
	
	/**
	 * 
	 * <p>Function: getOrderCode</p>
	 * <p>Description: 获取工单编号的block</p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-01-15 上午09:40:20 高强
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	private EiBlock getOrderCode() {
		
		EiBlock block = new EiBlock("cmes.ce.orderCode");

		EiColumn eiColumn = new EiColumn("fdKeyId");
		eiColumn.setType("C");
		block.addMeta(eiColumn);

		eiColumn = new EiColumn("fdCode");
		eiColumn.setType("C");
		block.addMeta(eiColumn);

		List<Map> _list = dao.query("ZMCEEquipmentOrder.queryInterface", null);

		block.setRows(_list);
		return block;
	}
}
